//
//  NGbbsTableCollectionViewCell.swift
//  NingguoForum
//
//  Created by zhengsw on 2025/7/17.
//  Copyright © 2025 zhengsw. All rights reserved.
//

import UIKit
import Kingfisher

class NGbbsTableCollectionViewCell: UICollectionViewCell {
    var icon: UIImageView
    var label: UILabel
    var model: ResponseCircleClassItemModel?
    lazy var countLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        return label
    }()
    override init(frame: CGRect) {
        
        label = UILabel()
        icon = UIImageView()
        
        super.init(frame: frame)
        self.isUserInteractionEnabled = true
        self.addSubview(icon)
        icon.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(5)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 40, height: 40))
        }
        label.font = UIFont.systemFont(ofSize: 15)
        label.textColor = RGB_COLOR(r: 48, g: 48, b: 48)
        self.addSubview(label)
        
        label.snp.makeConstraints { make in
            make.left.equalTo(icon.snp.right).offset(5)
            make.right.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        self.addSubview(countLabel)
        countLabel.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.right.equalTo(-5);
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func setModel(model:ResponseCircleClassItemModel){
        self.model = model
        icon.kf.setImage(with: URL(string: model.icon_url!))
        label.text = model.name
        guard let post_today = model.post_today,post_today > 0 else {
            countLabel.isHidden = true
            return
        }
        countLabel.isHidden = false
        countLabel.text = "\(post_today)"
    }

}
